package com.example.springboot.transaction.bean.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.springboot.transaction.bean.entity.AEntity;
import com.example.springboot.transaction.bean.mapper.AMapper;
import com.example.springboot.transaction.bean.service.AService;
import com.example.springboot.transaction.bean.service.BService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author: luojm
 * @create: 2020-12-29 15:55:50
 */
@Service
public class AServiceImpl extends ServiceImpl<AMapper, AEntity> implements AService {
    @Autowired
    private BService bService;

    @Override
    public void testA(){
        AEntity aEntity = new AEntity();
        testA1(aEntity);
        aEntity.setTA1("11");
        aEntity.setTA2("21");
        save(aEntity);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public void testA1(AEntity aEntity){
        aEntity.setTA1("12");
        aEntity.setTA2("22");
        save(aEntity);
        int i = 1/0;
    }

    @Override
    @Transactional
    public void testB() {
        AEntity aEntity = new AEntity();
        aEntity.setTA1("testB");
        aEntity.setTA2("testB");
        save(aEntity);
        bService.testB();
    }

    @Override
    public void testB1() {

    }
}
